package com.ssh;

public class Jump_45 {
	public static void main(String[] args) {
		int[] x = {2,3,0,1,4};
		System.out.println(jump1(x));
	}
	public static int jump1(int[] A) {
	    int sc = 0;
	    int e = 0;
	    int max = 0;
	    for(int i=0; i<A.length-1; i++) {
	        max = Math.max(max, i+A[i]);
	        if( i == e ) {
	            sc++;
	            e = max;
	        } 
	    }
	    return sc;
	}
	public static int jump(int[] nums) {
		int sum = 0,max = 0,t = 0,start = 0,length = nums[start];
		if (nums.length == 1) {
			return 0;
		}
		for (int i = start+1; i <= (start+length); i++) {
			System.out.println("i="+i);
			if ((start+length) >= (nums.length-1)) {
				sum++;
				break;
			}
			if (max < (i + nums[i])) {
				max = i + nums[i];
				System.out.println("max="+max);
				t = i;
				System.out.println("t1="+t);
			}
			System.out.println("start+length="+(start+length));
			if (i == (start+length)) {
				i = t;
				start = t;
				length = nums[start];
				sum++;
				if (max >= (nums.length-1)) {
					sum++;
					break;
				}
			}
		}
        return sum;
    }
	/*private static void j (int[] nums,int start,int length) {
		sum++;
		if ((start + length) >= (nums.length - 1)) {
			return;
		}
		int max = 0,t = 0;
		for (int i = start+1; i <= (start+length); i++) {
			if (max < (i + nums[i])) {
				max = i + nums[i];
				t = i;
			}
		}
		j (nums,t,nums[t]);
	}*/
}
